<?
include_once 'functionsPrjDet.php';
include 'headermenu.php';
	$dbh=dbConn();
	
	//aici se ia id-proiect din url-ul de legatura catre aceasta pagina
	 $idp=$_GET[rowid];
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
         <link rel="stylesheet" href="yui.css" type="text/css">
     
</head>

<body>

<div id="doc" class="yui-t7">

 <? //zona client ?>
   <div id="bd" role="main">
	<div class="yui-g">
    


   <h3> Clienti</h3>
     
    <?
	// se selecteaza randurile care contin id proiect din tabele de legatura dintre proiect si companie
    $result = returnQuery("Select * from project_companies where id_project=".$idp." and id_company_type=1 ;",$dbh);
	
	
	//####afisam inregistrarile in tabela:
	echo('<table>');
	echo('<tr> </tr>');
	while ($row = mysql_fetch_assoc($result)) 
	{
		$result2 = returnQuery("Select * from companies where id=".$row['id_company'].";",$dbh);
		$row2 = mysql_fetch_assoc($result2);
		echo "<tr><p>".$row2["name"]."</p></tr>";

	}
	echo('</table>');
	mysql_free_result($result);	
		
	?>

<!-- forma de selectare de companie pt clienti -->
  <? 

	   if(isset($_POST['cl_add']))
		{
		if($_POST["client"] != null) 
		
		
	{
			// $result5 = returnQuery("Select * from companies where name='".$_POST['id_client']."';",$dbh);
				//$row5 = mysql_fetch_assoc($result5);
				  
				$result3 = returnQuery("select * from companies where name = '".$_POST['client']."';",''); 
				$row3 = mysql_fetch_assoc($result3);
				mysql_query("INSERT INTO project_companies(id, id_project, id_company, id_company_type) VALUES(null, '".$idp."', '".$row3['id']."','1'); ") or die(mysql_error());
				//echo "e ciudat!!!!";
				//mysql_query("INSERT INTO project_companies(id, id_project, id_company, id_company_type) VALUES(null, '".$idp."', '".$_POST['id_client']."','1'); ") or die(mysql_error());  
		
			//refreshPage('http://localhost/methodology/');
		}
		else echo "e de cacat!!!!";
	}
	
	?>  <?  display(1);?>
 
  	</div>
 </div>
 
 <!-- zona pentru furnizor ------>
 
 <div id="bd" role="main">   
	<div class="yui-g">
	
	   <h3> Furnizori </h3>
  
<?
    // se selecteaza randurile care contin id proiect din tabele de legatura dintre proiect si companie 
    $result = returnQuery("Select * from project_companies where id_project=".$idp." and id_company_type=0 ;",$dbh);
	
	
	//####afisam inregistrarile in tabela:
	echo('<table>');
	while ($row = mysql_fetch_assoc($result)) 
	{
		$result2 = returnQuery("Select * from companies where id=".$row['id_company'].";",$dbh);
		$row2 = mysql_fetch_assoc($result2);
		echo "<tr><p>";

		echo "<td>".$row2["name"]."</td>";
		echo "</p></tr>";
	}
	echo('</table>');
	mysql_free_result($result);	
	?>
    
     
    
    <?
	if(isset($_POST['fz_add']))
	{
		if($_POST['furnizor'] != null) 
		{
			echo $_POST['furnizor'];
		    $result6 = returnQuery("Select * from companies where name='".$_POST['furnizor']."';",$dbh);
			$row6 = mysql_fetch_assoc($result6);
			mysql_query("INSERT INTO project_companies(id, id_project, id_company, id_company_type) VALUES(null, '".$idp."', '".$row6['id']."','0'); ") or die(mysql_error());  
			//	unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
		}
	}
    ?>
    <?  display(0);?>
    	</div>

	</div>
 
</div>
</body>
</html>

<?
	dbClose($dbh);
include 'footer.php'
?>
